package com.hengpeng.msls.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hengpeng.common.exception.ServiceResult;
import com.hengpeng.itfinbase.en.BorrowStatus;
import com.hengpeng.itfinbase.en.RewardRedPacketStatus;
import com.hengpeng.itfinbase.persist.Account;
import com.hengpeng.itfinbase.persist.BorrowInfo;
import com.hengpeng.itfinbase.persist.UserInfo;
import com.hengpeng.msls.vo.SessionMember;

@Controller
public class IndexController extends BaseController {
    @RequestMapping(value = "/index")
    public String index(HttpServletRequest request, ModelMap map) {
        int size = 8;
        SessionMember session = getSessionMember(request);
        if (session != null) {
            UserInfo userInfo = session.getUser();
            Account account = serviceFactory.getAccountService().getAccount(userInfo.getId());
            UserInfo user = serviceFactory.getUserInfoService().getUserInfoById(userInfo.getId());
            Long rewardRedPackageMoney = serviceFactory.getRedPacketService().countRedPacket(userInfo.getId(),new RewardRedPacketStatus[] {RewardRedPacketStatus.CANUSE});
            map.put("account", account);
            map.put("user", user);
            map.put("redMoney", rewardRedPackageMoney);
        }
        BorrowStatus[] status = { BorrowStatus.RAISE, BorrowStatus.END, BorrowStatus.LOANING,
                BorrowStatus.REPAYMENTING, BorrowStatus.REPAYMENTED };
        ServiceResult<List<BorrowInfo>> serviceResult = serviceFactory.getBorrowInfoService().queryList(status, null,
                1, size);
        map.put("productList", serviceResult.getReturnValue());// 投资推荐
        return "/page/index.jsp";
    }

    @RequestMapping(value = "/buylottery")
    public String buylottery(HttpServletRequest request, ModelMap map) {

        return "/page/index/ccb/index.jsp";
    }

    /**
     * <pre>
     * 根据会员店查询首页资讯列表
     * </pre>
     * 
     * @param request
     * @param map
     * @return
     */
    @RequestMapping(value = "/indexNews")
    public String indexNews(HttpServletRequest request, ModelMap map, String url, Integer size, Long logoGroupId) {
        return "";
    }

    @RequestMapping(value = "/indexNewsBody")
    @ResponseBody
    public ServiceResult<Object> indexNewsBody(HttpServletRequest request, ModelMap map, Integer currentPages,
            Integer pageSizes, Long logoGroupId) {
        // 默认首页

        ServiceResult<Object> retult = new ServiceResult<Object>();
        retult.setReturnValue(null);
        retult.setReturnObject(currentPages);
        return retult;
    }

    @RequestMapping(value = "/about")
    public String about(HttpServletRequest request, ModelMap map) {
        return "/page/wasu/description/about.jsp";
    }

    @RequestMapping(value = "/setBuy")
    public String setBuy(HttpServletRequest request, ModelMap map) {
        return "/page/wasu/description/setBuy.jsp";
    }

    @RequestMapping(value = "/getpwd")
    public String getpwd(HttpServletRequest request, ModelMap map) {
        return "/page/wasu/description/zhmm.jsp";
    }

    @RequestMapping(value = "/toRegister")
    public String toRegister(HttpServletRequest request, ModelMap map) {
        return "/page/wasu/mylottery/register.jsp";
    }

    @RequestMapping(value = "/toLogin")
    public String toLogin(HttpServletRequest request, ModelMap map) {
        return "/page/wasu/mylottery/login.jsp";
    }

    @RequestMapping(value = "/to306Login")
    public String to306Login(HttpServletRequest request, ModelMap map) {
        map.put("is306", "YES");
        return "/page/wasu/mylottery/login.jsp";
    }
}
